//
//  RECTableViewCell.m
//  CarFace
//
//  Created by dlios on 15/3/26.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "RECTableViewCell.h"

@interface RECTableViewCell ()
@property (nonatomic, retain) UIImageView *smallpicView;
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UILabel *timeLabel;
@property (nonatomic, retain) UILabel *replycountLabel;



@end

@implementation RECTableViewCell


- (void)dealloc
{
    [_smallpicView release];
    [_titleLabel release];
    [_timeLabel release];
    [_replycountLabel release];
    [_newlist release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
//        self.backgroundColor = [UIColor redColor];

        self.smallpicView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.smallpicView];
        [_smallpicView release];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.textAlignment = NSTextAlignmentLeft;
//        self.titleLabel.backgroundColor = [UIColor redColor];
        self.titleLabel.numberOfLines = 0;
        [self.contentView addSubview:self.titleLabel];
        [_titleLabel release];
        
        self.timeLabel = [[UILabel alloc] init];
        self.timeLabel.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:self.timeLabel];
        [_timeLabel release];
        
        self.replycountLabel = [[UILabel alloc] init];
        self.replycountLabel.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:self.replycountLabel];
        [_replycountLabel release];
        
        CGFloat fontNum = 12;
        self.titleLabel.font = [UIFont systemFontOfSize:17];
        self.timeLabel.font = [UIFont systemFontOfSize:fontNum];
        self.replycountLabel.font = [UIFont systemFontOfSize:fontNum];
        
        
       
        self.timeLabel.textColor = [UIColor lightGrayColor];
        self.replycountLabel.textColor = [UIColor lightGrayColor];
        
    

    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat width = self.contentView.bounds.size.width;
    CGFloat height = self.contentView.bounds.size.height;
    self.smallpicView.frame = CGRectMake(width / 80, width / 80, (height - width / 40) * 1.4 , height - width / 40);
    self.titleLabel.frame = CGRectMake((width / 3) + 10 , 7, (width * 2 / 3) - (width / 6 - 45), height / 2);
    self.timeLabel.frame = CGRectMake((width / 3) + 10, height / 2 + 20, width / 3 + 20, height / 4);
    self.replycountLabel.frame = CGRectMake((width  * 2 / 3) + 50, height / 2 + 20, width / 6, height / 4);
    

    if (0 == self.newlist.smallpic.length) {
        _newlist.smallpic = _newlist.smallimg;
    }
    
    NSString *smallpicStr = [self.newlist.smallpic stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:smallpicStr];
    [self.smallpicView setImageWithURL:url];
    
    self.titleLabel.text = self.newlist.title;
    self.timeLabel.text = self.newlist.time;
    NSString *string = [NSString stringWithFormat:@"%@", self.newlist.replycount];
    self.replycountLabel.text = [string stringByAppendingString:@"评论"];
    
}

//- (void)setNewlist:(Newslist *)newlist
//{
//    if (_newlist != newlist) {
//        [_newlist release];
//        _newlist = [newlist retain];
//    }
//
//    
//    
//    
//    
//
//}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
